home *** CD-ROM | disk | FTP | other *** search
/ Power Programmierung / Power-Programmierung (Tewi)(1994).iso / magazine / progjour / 1988 / 06 / ndpc386 / clock.asm next >
Assembly Source File  |  1988-09-01  |  3KB  |  101 lines

  1. ;
  2. ; CLOCK.ASM
  3. ;
  4. ; Author:    M. Steven Baker
  5. ; Date:        September 1, 1988
  6. ;
  7. ; a clock function for NDP C-386
  8. ; must assemble with Phar LAP 386asm
  9. ; C calling convention returning 1/100 seconds since midnite as a long
  10. ;    long t;
  11. ;    t = clock();
  12.  
  13. .386    ; required to generate 32-bit code/data
  14.  
  15. ; It is very important when linking to F77L-EM/32 program units that any data
  16. ; segments your assembly code uses have their class name as 'DATA' in order
  17. ; to link correctly.  In addition, you must also use the GROUP directive 
  18. ; to include the data in group DGROUP.  DS and ES are set to DGROUP by the 
  19. ; FORTRAN code, and must be set that way on return.  Your code segment must
  20. ; also be included in the group CGROUP, and include the directive:
  21. ; ASSUME DS:DGROUP, CS:CGROUP
  22.  
  23. dataseg        segment    dword
  24. dataseg        ends
  25. ;
  26. codeseg    segment dword er public use32
  27. assume    cs:codeseg, ds:dataseg
  28. ;
  29. ; The procedure names must be declared public to be addressable by
  30. ; other modules.
  31. ;
  32. public    _clock
  33.  
  34. align 4
  35.  
  36. _clock        proc    near
  37. ;
  38. ; Upon entry to any function, NDP C-386 has pushed arguments 
  39. ; onto the stack.  When all arguments have been dealt with, 
  40. ; NDPF-386 issues a near call to the named routine.
  41. ;
  42. ; log4 = example( int2, int4, int2a, int2a(3), dp, cmpx )
  43. ;          arg1  arg2  arg3     arg4   arg5 arg6
  44. ;
  45. ;    push    ebp        ; always do this... if EBP/ESP are used
  46. ;    mov    ebp, esp    ; and this (ebp must be preserved)
  47. ;
  48. ; The arguments are pushed right to left; thus, the first argument
  49. ; is closest to ebp.  At this point, the stack contains:
  50. ;
  51. ;    offset of argn
  52. ;         ...
  53. ;    offset of arg1 = IHR
  54. ;    return code offset  (EIP) }-- four byte address from near call
  55. ;    saved ebp    <-- ebp, esp
  56. ;
  57. ; The first argument address is now 8 bytes from ebp, referenced at [ebp+8].
  58. ; Note that the minimum argument displacement is 8 for subroutines and 12
  59. ; for functions.
  60. ;
  61. ;    t = clock();
  62. ;
  63.     mov    ah,2ch        ;DOS Get Time function
  64.     int    21h        ;returns CH=hour,   CL=minute
  65.                 ;        DH =second DL=hundredths
  66. ;                ;note this trashes CX and DX
  67. ;    mov    eax,60
  68. ;    mul    ch
  69.     movzx    eax,ch        ;start with hours
  70.     lea    eax,[eax+eax*4]    ; x 5   use some fast integer multiplies
  71.     lea    eax,[eax*4]    ; x 20
  72.     lea    eax,[eax+eax*2]    ; x 60
  73. ;
  74.     movzx    ecx,cl        ; zero top of register
  75.     add    eax,ecx        ; now add in minutes
  76.     lea    eax,[eax+eax*4]    ; x 5   use some fast integer multiplies
  77.     lea    eax,[eax*4]    ; x 20
  78.     lea    eax,[eax+eax*2]    ; x 60
  79. ;
  80.     movzx    ecx,dh
  81.     add    eax,ecx        ; add in seconds
  82.     lea    eax,[eax+eax*4]    ; x 5   use some fast integer multiplies
  83.     lea    eax,[eax*4]    ; x 20
  84.     lea    eax,[eax+eax*4]    ; x 100
  85.     movzx    ecx,dl
  86.     add    eax,ecx        ;now add in hundredths of seconds
  87. ;
  88.     ret
  89. _clock    endp
  90.  
  91.  
  92. codeseg        ends
  93.  
  94.     end
  95. ;
  96. ; Do not put any label name or expression after the end statement!  This
  97. ; defines a program entry point, which has already been defined by the
  98. ; Fortran MAIN module.
  99.  
  100.